package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    WmNewsService wmNewsService;

    @PostMapping("/list")
    public ResponseResult findList(@RequestBody WmNewsPageReqDto dto) {
        return this.wmNewsService.findList(dto);
    }


    @PostMapping("submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto wmNewsDto) {
        return this.wmNewsService.submitNews(wmNewsDto);
    }

    @GetMapping("/one/{id}")
    public ResponseResult findById(@PathVariable Integer id) {
        return this.wmNewsService.findById(id);
    }

    @GetMapping("/del_news/{id}")
    public ResponseResult deleteById(@PathVariable Integer id) {
        return this.wmNewsService.deleteById(id);
    }

    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto wmNewsDto) {
        return this.wmNewsService.downOrUp(wmNewsDto);
    }

    @PutMapping("/update")
    public ResponseResult updateWmNews(@RequestBody WmNews wmNews) {
        return this.wmNewsService.updateWmNews(wmNews);
    }

    @GetMapping("/findOne/{id}")
    public ResponseResult<WmNews> findWmUserById(@PathVariable("id") Integer id) {
        return this.wmNewsService.findWmUserById(id);

    }
    /**
     * 查询需要发布的文章id列表
     * @return
     */
    @ApiOperation("查询待发布文章id列表")
    @GetMapping("/findRelease")
    public ResponseResult<List<Integer>> findRelease() {
        return this.wmNewsService.findRelease();
    }

    @PostMapping("/list_vo")
    public ResponseResult findNewsList(@RequestBody NewsAuthDto newsAuthDto) {
        return this.wmNewsService.findNewsList(newsAuthDto);
    }
    @GetMapping("/one_vo/{id}")
    public ResponseResult findWmNewsVo(@PathVariable("id") Integer id) {
        return this.wmNewsService.findWmNewsVo(id);
    }

    @ApiOperation("人工审核通过 状态:4")
    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto dto) {
        return this.wmNewsService.authPass(dto);

    }

    @ApiOperation("人工审核失败 状态:2")
    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto dto) {
        return this.wmNewsService.authFail(dto);
    }
}
